import 'package:flutter/material.dart';

///切圆角
class ClipWidget extends StatelessWidget {
  final double radius; //圆角大小
  final Widget? child; //子控件
  final bool topLeft; //是否切左上角，默认是
  final bool topRight; //是否切右上角，默认是
  final bool bottomLeft; //是否切左下角，默认是
  final bool bottomRight; //是否切右下角角，默认是
  final Clip? clipBehavior;

  const ClipWidget({
    Key? key,
    this.child,
    this.radius = 10,
    this.topLeft = true,
    this.topRight = true,
    this.bottomLeft = true,
    this.bottomRight = true,
    this.clipBehavior,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    if (radius == 0) {
      return child ?? Container();
    } else {
      return ClipRRect(
        clipBehavior: clipBehavior ?? Clip.antiAlias,
        borderRadius: BorderRadius.only(
          topLeft: topLeft == true
              ? Radius.circular(radius)
              : Radius.zero,
          bottomLeft: bottomLeft == true
              ? Radius.circular(radius)
              : Radius.zero,
          topRight: topRight == true
              ? Radius.circular(radius)
              : Radius.zero,
          bottomRight: bottomRight == true
              ? Radius.circular(radius)
              : Radius.zero,
        ),
        child: child,
      );
    }
  }
}
